package org.tpdata.api;

import asserts.Asserts;
import utils.Contants;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import common.Data;
import common.Loginobject;
import common.RunCaseJson;
import common.SetUpTearDown;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.List;

import static common.TestStep.requestAndRespondBody;


@Feature("项目列表")
public class ProjectList extends SetUpTearDown {
    Logger log = Logger.getLogger(login.class);
    Data data = envSetUp();
/*    @BeforeClass

    public Data beforeclass() {
        JSONObject json= new JSONObject();
        json.put("userName", "112");
        json.put("passwd", "tP123456@");
        json.put("orgId", "75635");

        Response response= RunCaseJson.runCase(json,"post","api-auth/login");
        String jsonStr= response.asString();
//        JSONObject jsonObj=JSONObject.parseObject(jsonStr);
        Loginobject loginobject= JSONObject.parseObject(jsonStr,new TypeReference<Loginobject>(){}.getType());
       Data data= loginobject.getData();
       return data;
    }*/

    @Story("成功获取列表")
    @Test(description = "获取列表测试")
    public  void runCase()  {
        JSONObject json= new JSONObject();
        json.put("page", "1");
        json.put("access_token", data.getAccessToken());
        json.put("authToken",data.getAccessToken() );
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("size", "5");
//        json.put("", "");
        Response response=RunCaseJson.runCase(json,"get","/api-project/dme/project/list");
        String jsonStr= response.asString();
        log.info("响应报文："+jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        JSONObject data1= obj.getJSONObject("data");
//        JSONObject content=data1.getJSONObject("content");
        JSONArray contentArr=data1.getJSONArray("content");
        List<String> arr1= Arrays.asList("系统随访项目","01202","001","肺功能报告测试","221","wfwgwg");
//        Asserts.VerityArray(contentArr,arr1,"projectName");

        String url = RestAssured.baseURI + ":" + RestAssured.port + "/api-project/dme/project/list";
        requestAndRespondBody(url,json,jsonStr);
        boolean flag=Asserts.VerityArray(contentArr,arr1,"projectName");
        Assert.assertEquals(flag, Contants.ASSERT_SUCCESS);


    }

}
